<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
      <el-form-item :label="$t('terminal.identification')" prop="deviceCode">
        <el-input
          v-model="queryParams.deviceCode"
          :placeholder="$t('terminal.identification')"
          clearable
          style="width: 170px;"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('calling.commandType')" prop="type">
        <el-select
          v-model="queryParams.type"
          :placeholder="$t('calling.commandType')"
          clearable
          size="small"
          style="width: 170px;"
        >
          <el-option
            v-for="dict in commandType"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item :label="$t('program.status')" prop="status">
        <el-select
          v-model="queryParams.status"
          :placeholder="$t('program.status')"
          clearable
          size="small"
          style="width: 170px;"
        >
          <el-option
            v-for="dict in commandstatus"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('elButton.search') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('elButton.reset') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <div class="top-right-btn">
        <el-tooltip class="item" effect="dark" :content="$t('elButton.refresh')" placement="top">
          <el-button size="mini" circle icon="el-icon-refresh" @click="handleQuery" />
        </el-tooltip>
        <el-tooltip class="item" effect="dark" :content="showSearch ? $t('elButton.hideSearch') : $t('elButton.showSearch')" placement="top">
          <el-button size="mini" circle icon="el-icon-search" @click="showSearch=!showSearch" />
        </el-tooltip>
      </div>
    </el-row>

    <!-- 设备指令列表-->
    <el-table v-loading="loading" :data="list">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column :label="$t('equipment.number')" align="center" prop="id" width="150" />
      <el-table-column :label="$t('calling.commandType')" align="center" prop="type" width="100" :formatter="typeFormat" />
      <el-table-column :label="$t('terminal.identification')" align="center" prop="deviceCode" width="150" />
      <el-table-column :label="$t('program.status')" align="center" prop="status" width="150" :formatter="statusFormat" />
      <el-table-column :label="$t('calling.commandData')" align="center" prop="data" width="130" :show-overflow-tooltip="true" />
      <el-table-column :label="$t('calling.commandResult')" align="center" prop="result" width="200" :show-overflow-tooltip="true" />
      <el-table-column :label="$t('profile.deptName')" align="center" prop="deptId" :show-overflow-tooltip="true" />
      <el-table-column :label="$t('calling.commandTimes')" align="center" prop="times" :show-overflow-tooltip="true" />
      <el-table-column :label="$t('equipment.createTime')" align="center" prop="createTime" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column :label="$t('equipment.updateTime')" align="center" prop="updateTime" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { listChannelCut } from '@/api/ips/command'

export default {
  name: 'Command',
  data() {
    return {
      commandType: [{ label: '节目发布', value: '3' }, { label: '清空节目', value: '4' }, { label: '节目更新', value: '13' }],
      commandstatus: [{ label: '发送失败', value: '0' }, { label: '发送成功', value: '1' }],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 类型数据字典
      typeOptions: [],
      // 状态数据字典
      statusOptions: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        deviceCode: '',
        status: undefined,
        createTime: undefined,
        type: ''
      },
      // 显示搜索条件
      showSearch: true
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      console.log('111')
      this.loading = true
      listChannelCut(this.queryParams).then(response => {
        this.list = response.data
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1
      this.getList()
    },
    typeFormat(row, column) {
      return this.selectDictLabel(this.commandType, row.type)
    },
    statusFormat(row, column) {
      return this.selectDictLabel(this.commandstatus, row.status)
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
